package com.own.component.util.excel.util.read;

import com.own.component.util.excel.util.read.base.AbstractExcelRead;
import com.own.component.util.excel.util.read.config.ExcelReadCustomConfig;
import com.own.component.util.excel.util.read.function.resolve.CustomResolveFunction;
import com.own.component.util.excel.util.read.model.ResolveFileModel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * ExcelReadCustom
 *
 * @author chenxueli
 * @date 2022-06-15 03:14:15
 */
@Slf4j
@NoArgsConstructor
public class ExcelReadCustom<T> extends AbstractExcelRead<T, CustomResolveFunction<T>, ExcelReadCustomConfig<T>> {

    /**
     * 读取excel内容
     *
     * @param fileModel       文件信息
     * @param resolveFunction 解析数据的方法
     * @return 解析后的内容信息
     */
    @Override
    public List<T> read(ResolveFileModel fileModel, CustomResolveFunction<T> resolveFunction) {
        // 获取工作表
        var sheet = getSheet(fileModel.getInputStream());
        // 执行自定义解析的内容
        return resolveFunction.run(sheet, this::getResolveValue);
    }

    /**
     * 获取默认的配置信息
     *
     * @return 默认的配置信息
     */
    @Override
    protected ExcelReadCustomConfig<T> getDefaultConfig() {
        return new ExcelReadCustomConfig<>();
    }
}
